package com.heima.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcDemo01 {
    public static void main(String[] args) throws Exception{
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //获取连接
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db10", "root", "itheima888");
        //获取执行者对象
        Statement stat = con.createStatement();
        //执行sql语句，并接收返回的结果
        String sql = "select * from t_stu";
        ResultSet rs = stat.executeQuery(sql);
        //处理结果。遍历
        while(rs.next()){
            System.out.println(rs.getInt("id")+"\t"+rs.getString("name")+"\t"+rs.getInt("age")
            +"\t"+rs.getInt("score"));
        }
        //释放资源
        con.close();
        stat.close();
        rs.close();
    }
}
